import java.util.Arrays;

public class test2 {
    //力扣  740.删除并获得点数
    public int deleteAndEarn(int[] nums) {
        //预处理
        Arrays.sort(nums);
        int n = nums.length;
        int[] newnums = new int[nums[n-1]+1];
        for(int num:nums){
            newnums[num] +=num;
        }
        //这里和打家劫舍的一样
        int n1 = newnums.length;
        int[] dpf = new int[n1];
        int[] dpg = new int[n1];
        dpf[0] = newnums[0];
        for(int i = 1;i<n1;i++){
            dpf[i] = dpg[i-1]+newnums[i];
            dpg[i] = Math.max(dpf[i-1],dpg[i-1]);
        }
        return Math.max(dpf[n1-1],dpg[n1-1]);

    }
}
